import 'package:flutter/material.dart';
import './contact_vo.dart';

class ContactItem extends StatelessWidget {
  final ContactVO? item;
  final String? titleName;
  final String? imageName;

  ContactItem({this.item,  this.titleName,  this.imageName});


  @override
  Widget build(BuildContext context) {

    // 定义临时变量来存储 URL
    final String defaultAvatarUrl = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2024%2F05%2F1018%2F283462633_4_20240510061136195&refer=http%3A%2F%2Fimage109.360doc.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1721996623&t=45d2c2dff6d77c4e6e873c47f548e4e5';

    // TODO: implement build
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border:
            Border(bottom: BorderSide(width: 0.5, color: Color(0xFFd9d9d9))),
      ),
      height: 52.0,
      child: TextButton(
        onPressed: () {},
        // style: TextButton.styleFrom(
        //   padding: EdgeInsets.zero, // 移除内边距
        // ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            imageName == null
                ? Image.network(
              item?.avatarUrl ?? defaultAvatarUrl,
              width: 36.0,
              height: 36.0,
              scale: 0.9,
              errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
                return Image.network(
                  defaultAvatarUrl,
                  width: 36.0,
                  height: 36.0,
                );
              },

            )
                : Image.asset(
                    imageName  ?? '',
                    width: 36.0,
                    height: 36.0,
                  ),
            Container(
              margin: const EdgeInsets.only(left: 12.0),
              child: Text(
                titleName ?? (item?.name ?? '暂时'),
                style: TextStyle(fontSize: 18.0,color: Color(0xFF353535)),
                maxLines: 1,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
